<template>

  <el-dialog v-model="dialogFormVisible" title="详情" width="500">
    <!-- 详情 -->
    <div class="artic">
      <el-form :model="form" label-width="auto" style="max-width: 600px">
        <!-- 业务类型 -->
        <el-form-item>
          <el-select v-model="form.region" placeholder="业务类型">
            <el-option label="Zone one" value="shanghai" />
            <el-option label="Zone two" value="beijing" />
          </el-select>
        </el-form-item>
        <!-- 业务标题 -->
        <el-form-item>
          <el-input v-model="form.name" placeholder="业务标题" />
        </el-form-item>
        <!-- 业务内容 -->
        <el-form-item>
          <el-input v-model="form.desc" type="textarea" placeholder="业务内容" />
        </el-form-item>
        <!-- 选择文件 -->
        <el-form-item>
          <el-upload v-model:file-list="fileList" action="http://oa.web.sdbaizhi.com/api/oa/web.Apply/upload"
            list-type="text" :on-error="handleUploadError" :on-success="handleUploadSuccess">
            <el-button type="default">选择文件</el-button>
          </el-upload>
        </el-form-item>
        <!-- 图片上传 -->
        <el-form-item label="图片">
          <el-upload v-model:file-list="imageList" action="http://oa.web.sdbaizhi.com/api/oa/web.Apply/upload"
            list-type="picture-card" :on-preview="handlePictureCardPreview" :on-error="handleUploadError"
            :on-success="handleUploadSuccess">
            <el-icon>
              <Plus />
            </el-icon>
          </el-upload>
        </el-form-item>
        <!-- 选择审批人 -->
        <el-form-item>
          <el-radio-group v-model="form.resource">
            <el-radio value="Sponsor">张三</el-radio>
            <el-radio value="Venue">李四</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit" size="200px">提交</el-button>
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogFormVisible = false">Cancel</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">
          Confirm
        </el-button>
      </div>
    </template>
  </el-dialog>


  <el-dialog v-model="dialogTableVisible" title="Shipping address" width="800">
    <el-table :data="gridData">
      <el-table-column property="date" label="Date" width="150" />
      <el-table-column property="name" label="Name" width="200" />
      <el-table-column property="address" label="Address" />
    </el-table>
  </el-dialog>
  <div class="all">
    <el-button class="btn" plain @click="dialogTableVisible = true" type='primary'>
      送货地址
    </el-button>
    <el-button plain @click="dialogFormVisible = true">
      详情
    </el-button>
    <el-table :data="tableData" style="width: 100%" max-height="700">
      <el-table-column fixed prop="date" label="Date" width="150" />
      <el-table-column prop="name" label="Name" width="120" />
      <el-table-column prop="state" label="State" width="120" />
      <el-table-column prop="city" label="City" width="120" />
      <el-table-column prop="address" label="Address" width="600" />
      <el-table-column prop="zip" label="Zip" width="120" />
      <el-table-column fixed="right" label="Operations" min-width="120">
        <template #default="scope">
          <el-button link type="primary" size="small" @click.prevent="deleteRow(scope.$index)">
            Remove
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-button class="mt-4" style="width: 100%" @click="onAddItem">
      Add Item
    </el-button>
  </div>
</template>

<script lang="ts" setup>
import { reactive, ref } from "vue";
import dayjs from 'dayjs'
// 头像
// 详情
const form = reactive({
  name: "",
  region: "",
  date1: "",
  date2: "",
  delivery: false,
  type: [],
  resource: "",
  desc: "",
});
import { ElMessage } from 'element-plus';
const imageList = ref([])
const fileList = ref([])
// 图片上传
// 上传成功
const handleUploadSuccess = ((res, uploadFile) => {
  console.log(uploadFile)
  if (res.code == 1) {
    ElMessage.success(res.msg)
  } else {
    ElMessage.error(res.msg)
  }
})
const previewImgDialogVisible = ref(false)
const dialogImageUrl = ref('')
const handlePictureCardPreview = ((uploadFile) => {
  dialogImageUrl.value = uploadFile.url
  previewImgDialogVisible.value = true
})
// 上传失败
const handleUploadError = (() => {
  ElMessage.error('上传失败')
})
const onSubmit = () => {
  console.log("submit!");
};
const dialogFormVisible = ref(false)

// 对话框
const dialogTableVisible = ref(false)
const gridData = [
  {
    date: '2016-05-02',
    name: 'John Smith',
    address: 'No.1518,  Jinshajiang Road, Putuo District',
  },
  {
    date: '2016-05-04',
    name: 'John Smith',
    address: 'No.1518,  Jinshajiang Road, Putuo District',
  },
  {
    date: '2016-05-01',
    name: 'John Smith',
    address: 'No.1518,  Jinshajiang Road, Putuo District',
  },
  {
    date: '2016-05-03',
    name: 'John Smith',
    address: 'No.1518,  Jinshajiang Road, Putuo District',
  },
]
const now = new Date()
const tableData = ref([
  {
    date: '2016-05-01',
    name: 'Tom',
    state: 'California',
    city: 'Los Angeles',
    address: 'No. 189, Grove St, Los Angeles',
    zip: 'CA 90036',
  },
  {
    date: '2016-05-02',
    name: 'Tom',
    state: 'California',
    city: 'Los Angeles',
    address: 'No. 189, Grove St, Los Angeles',
    zip: 'CA 90036',
  },
  {
    date: '2016-05-03',
    name: 'Tom',
    state: 'California',
    city: 'Los Angeles',
    address: 'No. 189, Grove St, Los Angeles',
    zip: 'CA 90036',
  },
])

const deleteRow = (index: number) => {
  tableData.value.splice(index, 1)
}

const onAddItem = () => {
  now.setDate(now.getDate() + 1)
  tableData.value.push({
    date: dayjs(now).format('YYYY-MM-DD'),
    name: 'Tom',
    state: 'California',
    city: 'Los Angeles',
    address: 'No. 189, Grove St, Los Angeles',
    zip: 'CA 90036',
  })
}
</script>
<style scoped lang="scss">
.artic {
  background-color: #fff;
  padding: 20px;

  .demo-image__placeholder .block {
    padding: 30px 0;
    text-align: center;
    border-right: solid 1px var(--el-border-color);
    display: inline-block;
    width: 49%;
    box-sizing: border-box;
    vertical-align: top;
  }

  .demo-image__placeholder .demonstration {
    display: block;
    color: var(--el-text-color-secondary);
    font-size: 14px;
    margin-bottom: 20px;
  }

  .demo-image__placeholder .el-image {
    padding: 0 5px;
    max-width: 300px;
    max-height: 200px;
  }

  .demo-image__placeholder.image-slot {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    background: var(--el-fill-color-light);
    color: var(--el-text-color-secondary);
    font-size: 14px;
  }

  .demo-image__placeholder .dot {
    animation: dot 2s infinite steps(3, start);
    overflow: hidden;
  }

  .choose1 {
    margin-top: 10px
  }

  .top {
    border: 1px solid red;

    .all {
      width: 80%;
      display: flex;
      justify-content: space-between
    }
  }
}

.all {
  padding: 1%;
  background-color: #fff;
}

.btn {
  margin-top: 1%;
  margin-bottom: 1%;
}
</style>
